#import "CarLrpPlugin.h"
//#if __has_include(<car_lrp_plugin/car_lrp_plugin-Swift.h>)
//#import <car_lrp_plugin/car_lrp_plugin-Swift.h>
//#else
//// Support project import fallback if the generated compatibility header
//// is not copied when this plugin is created as a library.
//// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
//#import "car_lrp_plugin-Swift.h"
//#endif


#import "CameraViewController.h"

@implementation CarLrpPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
//  [SwiftCarLrpPlugin registerWithRegistrar:registrar];
    FlutterMethodChannel* channel = [FlutterMethodChannel
                                     methodChannelWithName:@"car_lrp_plugin"
                                     binaryMessenger:[registrar messenger]];
    CarLrpPlugin* instance = [[CarLrpPlugin alloc] init];
    [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result
{
    if ([@"getPlatformVersion" isEqualToString:call.method])
    {
        result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
    }
    else if ([@"openScan" isEqualToString:call.method])
    {
        /**
         *
         *  *
         */
        
        CameraViewController* video = [CameraViewController new];
        
        video.resultCB = ^(NSString* text, UIImage* image) {
//            self.imageView.image = image;
//            self.resultLabel.text = text;
            if (text!=nil) {
//                NSData *imageData = UIImagePNGRepresentation(image);
//                const uint8_t *uint = (uint8_t*)[imageData bytes];
                result(@{@"code":text});
            }
        };
        UIViewController *vc = [[UIApplication sharedApplication] delegate].window.rootViewController;
        video.modalPresentationStyle = UIModalPresentationFullScreen;
        [vc showDetailViewController:video sender:nil];
    }
}


@end
